package thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author liuchaoqun
 * @date 2022/7/1
 * @Description callable接口和feature
 */
public class AysnDemo {
    public static void main(String[] args) throws InterruptedException {
        ReturnTask task = new ReturnTask();
        FutureTask futureTask = new FutureTask(task);
        Thread thread = new Thread(futureTask, "测试线程");
        thread.start();
        Thread.sleep(500);
        System.out.println("让子弹飞");
        for (int i = 0; i < 5 / 2; i++) {
            int j = i * 10000;
        }
        System.out.println("获取并发任务执行的时间");
        try {
            System.out.println(thread.getName() + "------线程占用时间-----" + futureTask.get());
        } catch (ExecutionException e) {
            e.printStackTrace();

        }
        System.out.println("运行结束");

    }
}
